package com.mall.security;

import com.central.common.utils.PwdEncoderUtil;
import org.springframework.security.crypto.password.PasswordEncoder;

public class DefaultPasswordEncoder implements PasswordEncoder {

    public DefaultPasswordEncoder() {
        this(-1);
    }
    public DefaultPasswordEncoder(int strength) {
    }

    public static void main(String[] args) {
        String md5 = PwdEncoderUtil.getDelegatingPasswordEncoder("MD5").encode("123456");
        System.out.println(md5);
    }

    /**
     * 密码加密逻辑
     * @param charSequence
     * @return
     */
    @Override
    public String encode(CharSequence charSequence) {
        String password = PwdEncoderUtil.getDelegatingPasswordEncoder("MD5").encode(charSequence.toString());
        return password;
    }

    /**
     * 密码对比逻辑
     * @param charSequence
     * @param password
     * @return
     */
    @Override
    public boolean matches(CharSequence charSequence, String password) {
        boolean equalsResult = PwdEncoderUtil.getDelegatingPasswordEncoder("MD5").matches(charSequence.toString(), password);
        return equalsResult;
    }

}
